import { _decorator, Component, director, Node, Toggle, tween, v2, v3 } from 'cc';
import { AdComponent } from '../AdComponent';
import { AudioMgr, ENUM_CLIP } from '../Tool/AudioMgr';
import DatasSpace from '../Tool/DatasSpace';
const { ccclass, property } = _decorator;

@ccclass('Setting')
export class Setting extends Component {

  @property(Toggle) toggle_vibrate: Toggle = null;
  @property(Toggle) toggle_music: Toggle = null;

  @property(Node)
  viewNode: Node = null;

  btnClose() {
    AudioMgr.Instance.play(ENUM_CLIP.Click);

    this.btnCloseSetting();
  }

  start() {
    // AdComponent.Instance.show5X5CustomAd();
    AdComponent.Instance.showInterstitialFullShow();
    // tween(this.viewNode).to(0.3, { position:v3(this.viewNode.getPosition().x,-50,0), scale:v3(1.2,0.8,0)}, { easing: 'smooth' }).to(0.3, { position: v3(0,0,0), scale:v3(1,1,0) }, { easing: 'backInOut' }).to(0.3, { scale:v3(1.1,0.9,0)}, { easing: 'backInOut' }).to(0.1, { scale:v3(1,1,0) }, { easing: 'backInOut' }).call(() => {
    // }).start();
    AdComponent.Instance.showBannerAd();

    if (this.toggle_music) {
      this.initSetting();
    }
  }

  protected onDestroy(): void {
    AdComponent.Instance.hideBannerAd();
  }

  btnCloseSetting() {
    // AdComponent.Instance.instance.playAudio(2);
    // AdComponent.Instance.hide5X5customAd();
    tween(this.viewNode).to(0.5, { position: v3(0, this.viewNode.getPosition().y + 1600, 0) }, { easing: 'backInOut' }).call(() => {
      this.node.removeFromParent();
      this.node.destroy();

    }).start();
  }

  // update(deltaTime: number) {

  // }

  initSetting() {
    this.toggle_vibrate.isChecked = false;
    this.toggle_music.isChecked = DatasSpace.Instance.GameSound ? true : false;
  }

  btnMusic() {
    DatasSpace.Instance.GameSound = this.toggle_music.isChecked ? 1 : 0;
    console.log(DatasSpace.Instance.GameSound)
  }
}


